<template>
	<view class="Lu-balance-box">
		<view class="Lu-balance-image">
			<image class="Lu-balance-img" src="/static/image/banlace.png"></image>
		</view>
		<view class="Lu-balance-yu">
			<view class="Lu-balance-tit">收益余额</view>
			<view class="Lu-balance-money">￥{{userInfo.blance}}</view>
		</view>
		<view class="Lu-balance-btn">
			<view class="Lu-balance-Cash" @click="balancemoney">提现</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import md5 from 'js-md5';
	export default {
		computed: {
			...mapState(['hasLogin','userInfo','openId','apiUrl'])
		},
		methods:{
			balancemoney:function(){
				if(this.userInfo.blance > 100){
					const shortName = this.openId.substring(0,this.userInfo.id%10) + this.userInfo.blance*100;
					uni.request({
						url:this.apiUrl + 'api/withdraw',
						data:{
							price:this.userInfo.blance*100,
							sign:md5(shortName),
						},
						method:'POST',
						header:{
							openid:this.openId
						},
						success: (res) => {
							uni.showModal({
								title:'提现成功，须等待3-5个工作日资金到账',
								content:'提现成功，须等待3-5个工作日资金到账'
							})
						}
					})
				}else{
					uni.showModal({
						title:'余额不足，满100才可提现',
						content:'余额不足，满100才可提现'
					})
				}
				
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #f5f5f5;
	}
	.Lu-balance-box{
		padding-top: 120rpx;
		.Lu-balance-image{
			width: 94rpx;
			height: 94rpx;
			margin: 0 auto;
			.Lu-balance-img{
				width: 100%;
				height: 100%;
			}
		}
		.Lu-balance-yu{
			margin-top: 80rpx;
			text-align: center;
			.Lu-balance-tit{
				font-size: 30rpx;
				color: #333333;
			}
			.Lu-balance-money{
				font-size: 80rpx;
				color: #333333;
			}
		}
		.Lu-balance-btn{
			width: 610rpx;
			height: 90rpx;
			background-image: url(~@/static/image/business/btnbg.png);
			background-size:610rpx 90rpx;
			background-repeat: no-repeat;
			line-height: 90rpx;
			text-align: center;
			margin: 0 auto;
			margin-top: 520rpx;
			.Lu-balance-Cash{
				font-size: 36rpx;
				color: #ffffff;
			}
		}
	}
</style>
